/**
 * 获取权限 (林海)
 * @param action string 操作方法
 * @returns {boolean} 是否有权限
 */
import store from '@/store' //项目的vuex实例
export default {
    install(Vue) {
        Object.defineProperty(Vue.prototype.$bui, 'hasPermission', {
            value: function(action) {
                if (!action) return false
                let hash = window.location.hash;
                if (hash.indexOf('?') > 0) hash = hash.substring(0, hash.indexOf('?'))
                let permission =
                    store.getters.permissions[
                        hash
                            .split('/')[1]
                            .replace(/^(\/bui_|\/pages_)/, '')
                            .replace(/_/g, ':')
                            .replace(/\//g, '') +
                            ':' +
                            action
                    ];
                if (!permission) return false
                return permission;
            }
        })
    }
}
